package conditions.operators

import conditions.BooleanNode
import values.ValueType;
import values.Variable

/**
 * True if the collection contains the value.
 * @author Pablo Pazos
 *
 */
class Contains extends BooleanNode {

   /**
    * Referencias a variables o parametros de los cuales voy a obtener el valor.
    */
   Variable collection
   Variable value
   
   public Contains() {}
   
   public Contains(Variable collection, Variable value)
   {
      if (collection.type != ValueType.COLLECTION) throw new IllegalArgumentException("First param should be a collection and is a "+ collection.type)
      this.collection = collection
      this.value = value
   }
  
   @Override
   public boolean evaluate()
   {
      println "  contains " + collection.value + " > " + value.value
      return collection.value.contains(value.value)
   }
   
   /**
   * Necesario para implementar el clone
   */
//   boolean equals(Object other)
//   {
//      other instanceof Contains && this.v1.equals(other.v1) && this.v2.equals(other.v2)
//   }
}